package com.eleventwelve.iris.core.bean;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.json.simple.JSONObject;

public class JSONKeyObject implements JSONSerializable {
	private JSONObject obj;
	private Long key;

	public JSONKeyObject(Long key, JSONObject obj) {
		this.key = key;
		this.obj = obj;
	}

	@SuppressWarnings("unchecked")
	public JSONObject toJSONObject() {
		JSONObject keyVal = new JSONObject();
		keyVal.put("key", this.getKey());
		keyVal.put("data", this.getObj());
		return keyVal;
	}

	public JSONObject getObj() {
		return obj;
	}

	public void setValue(JSONObject obj) {
		this.obj = obj;
	}

	public Long getKey() {
		return key;
	}

	public void setKey(Long key) {
		this.key = key;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((key == null) ? 0 : key.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		JSONKeyObject other = (JSONKeyObject) obj;
		if (key == null) {
			if (other.key != null)
				return false;
		} else if (!key.equals(other.key))
			return false;
		return true;
	}
	
	@Override
	public String toString() {
		return new ToStringBuilder(this)
			   .append(this.key)
			   .append(this.obj)
			   .toString();
	}

}
